﻿const express = require('express')
const app = express()
var categoryList = require('./mock/categoryList.json')//加载本地数据文件
var cateProducts = require('./mock/cateProducts.json')
// var goods = require('./mock/goods.json')
var goods = require('./mock/goods2.json')
var goodsService = require('./mock/goodsService.json')
var mallRecList = require('./mock/mallRecList.json')
var searchCategories = require('./mock/searchCategories.json')
var tabs = require('./mock/tabs.json')
var orders = require('./mock/orderList.json')
var searchResult = require('./mock/searchResult.json')
var confirmOrder = require('./mock/confirmOrder.json')
var addressList = require('./mock/addressList.json')
var footprint = require('./mock/footprint.json')
var couponsList = require('./mock/couponsList.json')
var unused = require('./mock/unused.json')
var overdue = require('./mock/overdue.json')
var mallGoodsList = require('./mock/mallGoodsList.json')
var mallCollection = require('./mock/mallCollection.json')
var goodsLikes = require('./mock/goodsLikes.json')

var apiRoutes = express.Router()
app.use('/json', apiRoutes)

module.exports = {

    devServer: {
        port: 8080,
        proxy: {
            '/v5': {
                target: 'http://api.yangkeduo.com'
            },
            '/api': {
                target: 'http://api.yangkeduo.com'
            },
            '/operation': {
                target: 'http://api.yangkeduo.com'
            },
            '/search_hotquery': {
                target: 'http://api.yangkeduo.com'
            },
            '/search_suggest': {
                target: 'http://api.yangkeduo.com'
            },
            '/recommendation': {
                target: 'http://api.yangkeduo.com'
            },
            '/mall': {
                target: 'http://api.yangkeduo.com'
            },
            '/pinduoduo': {
                target: 'http://localhost:8081'
            }
        },
        before: app => {
            app.get('/json/categoryList', (req, res) => {
                res.json({
                    error: 0,
                    data: categoryList
                })
            })
            app.get('/json/tabs', (req, res) => {
                res.json({
                    error: 0,
                    data: tabs
                })
            })
            app.get('/json/cateProducts', (req, res) => {
                res.json({
                    error: 0,
                    data: cateProducts
                })
            })
            app.get('/json/goods', (req, res) => {
                res.json({
                    error: 0,
                    data: goods
                })
            })
            app.get('/json/goodsService', (req, res) => {
                res.json({
                    error: 0,
                    data: goodsService
                })
            })
            app.get('/json/mallRecList', (req, res) => {
                res.json({
                    error: 0,
                    data: mallRecList
                })
            })
            app.get('/json/searchCategories', (req, res) => {
                res.json({
                    error: 0,
                    data: searchCategories
                })
            })
            app.get('/json/searchResult', (req, res) => {
                res.json({
                    error: 0,
                    data: searchResult
                })
            })
            app.get('/json/orders', (req, res) => {
                res.json({
                    error: 0,
                    data: orders
                })
            })
            app.get('/json/confirmOrder', (req, res) => {
                res.json({
                    error: 0,
                    data: confirmOrder
                })
            })
            app.get('/json/addressList', (req, res) => {
                res.json({
                    error: 0,
                    data: addressList
                })
            })
            app.get('/json/footprint', (req, res) => {
                res.json({
                    error: 0,
                    data: footprint
                })
            })
            app.get('/json/couponsList', (req, res) => {
                res.json({
                    error: 0,
                    data: couponsList
                })
            })
            app.get('/json/unused', (req, res) => {
                res.json({
                    error: 0,
                    data: unused
                })
            })
            app.get('/json/overdue', (req, res) => {
                res.json({
                    error: 0,
                    data: overdue
                })
            })
            app.get('/json/mallGoodsList', (req, res) => {
                res.json({
                    error: 0,
                    data: mallGoodsList
                })
            })
            app.get('/json/mallCollection', (req, res) => {
                res.json({
                    error: 0,
                    data: mallCollection
                })
            })
            app.get('/json/goodsLikes', (req, res) => {
                res.json({
                    error: 0,
                    data: goodsLikes
                })
            })

        }
    },
    lintOnSave: true,
    css: {
        loaderOptions: {
            postcss: {
                plugins: [
                    require('postcss-pxtorem')({
                        rootValue: 100, // 换算的基数
                        selectorBlackList: ['weui', 'mu'], // 忽略转换正则匹配项
                        propList: ['*'],
                    }),
                ]
            }
        }
    },
}